<template>
  <!-- 实名信息 -->
  <Top-Page>
    <cu-custom bgColor="bg-gradual-white-3" :isBack="true">
      <template #content>实名信息</template>
    </cu-custom>

    <Field
      rightIcon
      disabled
      label="姓名"
      placeholder="去填写"
      v-model="userInfo.user_name"
      @click="toSetValue('user_name', '您的真实姓名', `&valueType=name&text=${userInfo.user_name || ''}`)"
    />

    <Field
      rightIcon
      disabled
      autosize
      label="身份证号"
      placeholder="去填写"
      v-model="userInfo.identity"
      @click="toSetValue('identity', '您的真实身份证', `&valueType=IDcard&text=${userInfo.identity || ''}`)"
    />

    <Field
      rightIcon
      disabled
      autosize
      label="身份证住址"
      placeholder="去填写"
      v-model="userInfo.identity_address"
      @click="toPicker"
    />
    <!-- @click="toSetValue('identity_address', '您的真实身份证住址', `&text=${userInfo.identity_address || ''}`)" -->
  </Top-Page>
</template>

<script>
import Cell from "@/components/Cell/Cell.vue";
import pinia from "@/store/index";
import { useloginStore } from "@/store/login";
const loginStore = useloginStore(pinia);
import { saveInfo } from "@/hooks/useSaveChanges";
export default {
  data() {
    return {
      saveInfo,
      loginStore,
      userInfo: {},
    };
  },
  components: { Cell },
  onShow() {
    const app = getApp();
    const modifyData = app.globalData.modifyData;
    console.log(modifyData, "modifyData");
    if (modifyData && JSON.stringify(modifyData) != "{}") {
      if (["region"].includes(modifyData.type)) {
        this.userInfo["identity_address"] = modifyData.value.label.join("");
        this.submit();
      } else {
        this.userInfo[modifyData.type] = modifyData.value;
      }
    }
    setTimeout(() => {
      app.globalData.modifyData = null;
    }, 100);
  },
  mounted() {
    this.userInfo = JSON.parse(JSON.stringify(loginStore.userInfo));

    // 如果保存成功，则更新全局数据
    if (res && res.success) {
      const app = getApp();
      app.globalData.modifyData = {
        value: this.value,
        type: this.type,
      };
    }
  },
  methods: {
    async submit() {
      const res = await this.saveInfo(this.userInfo);
      console.log(res);
    },
    toPicker() {
      uni.navigateTo({
        url: `/pages/rest/picker-region/picker-region?type=region`,
      });
    },
    //设置/修改 内容
    toSetValue(type, title, extra) {
      uni.navigateTo({
        url: `/pages/rest/modify/modify?type=${type}&title=${title}${
          extra ?? ""
        }`,
      });
    },
  },
};
</script>

<style lang="scss" scoped>
@import url("./index.scss");
</style>
